package com.transitionseverywhere;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.animation.TypeEvaluator;
import android.content.Context;
import android.graphics.Rect;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Property;
import android.view.View;
import android.view.ViewGroup;
import com.transitionseverywhere.utils.RectEvaluator;
import com.transitionseverywhere.utils.ViewUtils;

/* loaded from: classes.dex */
public class ChangeClipBounds extends Transition {
    private static final String PROPNAME_BOUNDS = "android:clipBounds:bounds";
    private static final String TAG = "ChangeTransform";
    public static final Property<View, Rect> VIEW_CLIP_BOUNDS;
    private static final String PROPNAME_CLIP = "android:clipBounds:clip";
    private static final String[] sTransitionProperties = {PROPNAME_CLIP};

    static {
        if (Build.VERSION.SDK_INT >= 14) {
            VIEW_CLIP_BOUNDS = new Property<View, Rect>(Rect.class, "clipBounds") { // from class: com.transitionseverywhere.ChangeClipBounds.1
                @Override // android.util.Property
                public void set(View view, Rect rect) {
                    ViewUtils.setClipBounds(view, rect);
                }

                @Override // android.util.Property
                public Rect get(View view) {
                    return ViewUtils.getClipBounds(view);
                }
            };
        } else {
            VIEW_CLIP_BOUNDS = null;
        }
    }

    public ChangeClipBounds() {
    }

    public ChangeClipBounds(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
    }

    @Override // com.transitionseverywhere.Transition
    public String[] getTransitionProperties() {
        return sTransitionProperties;
    }

    private void captureValues(TransitionValues transitionValues) {
        View view = transitionValues.view;
        if (view.getVisibility() == 8) {
            return;
        }
        Rect clipBounds = ViewUtils.getClipBounds(view);
        transitionValues.values.put(PROPNAME_CLIP, clipBounds);
        if (clipBounds == null) {
            transitionValues.values.put(PROPNAME_BOUNDS, new Rect(0, 0, view.getWidth(), view.getHeight()));
        }
    }

    @Override // com.transitionseverywhere.Transition
    public void captureStartValues(TransitionValues transitionValues) {
        captureValues(transitionValues);
    }

    @Override // com.transitionseverywhere.Transition
    public void captureEndValues(TransitionValues transitionValues) {
        captureValues(transitionValues);
    }

    @Override // com.transitionseverywhere.Transition
    public Animator createAnimator(ViewGroup viewGroup, TransitionValues transitionValues, TransitionValues transitionValues2) {
        if (transitionValues == null || transitionValues2 == null || !transitionValues.values.containsKey(PROPNAME_CLIP) || !transitionValues2.values.containsKey(PROPNAME_CLIP)) {
            return null;
        }
        Rect rect = (Rect) transitionValues.values.get(PROPNAME_CLIP);
        Rect rect2 = (Rect) transitionValues2.values.get(PROPNAME_CLIP);
        if (rect == null && rect2 == null) {
            return null;
        }
        if (rect == null) {
            rect = (Rect) transitionValues.values.get(PROPNAME_BOUNDS);
        } else if (rect2 == null) {
            rect2 = (Rect) transitionValues2.values.get(PROPNAME_BOUNDS);
        }
        if (rect.equals(rect2)) {
            return null;
        }
        ViewUtils.setClipBounds(transitionValues2.view, rect);
        return ObjectAnimator.ofObject(transitionValues2.view, (Property<View, V>) VIEW_CLIP_BOUNDS, (TypeEvaluator) new RectEvaluator(new Rect()), (Object[]) new Rect[]{rect, rect2});
    }
}
